package com.cqggrw.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.alibaba.fastjson.JSON;
import com.cqggrw.dao.TouPiaoDaoI;
import com.cqggrw.dao.impl.TouPiaoDaoImpl;
import com.cqggrw.domain.TPiao;
import com.cqggrw.service.TouPiaoServiceI;

public class TouPiaoServiceImpl implements TouPiaoServiceI {
	
	private TouPiaoDaoI dao = new TouPiaoDaoImpl();

	public boolean add(TPiao t) {
		
		String falg = UUID.randomUUID().toString();
		
		dao.add(falg, t.getName());
		for(String str : t.getOption()) {
			dao.addOpt(falg, str);
		}
		
		return true;
	}

	public boolean del(Integer id) {
		return dao.del(id);
	}

	public boolean modify(TPiao t) {
		return dao.modify(t);
	}

	public TPiao getOne(TPiao tp) {
		tp = new TPiao();
		tp.setId(dao.getLastId());
		tp = dao.getOne(tp);
		tp.setTp(dao.getOptList(tp.getId()));
		return tp;
	}

	public Object get() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("total", dao.getCount());
		map.put("rows", dao.get());
		return dao.get();
	}

	public TPiao getTp(TPiao tp) {
		tp = dao.getOne(tp);
		tp.setTp(dao.getOptList(tp.getId()));
		System.out.println(JSON.toJSONString(tp));
		return tp;
	}

	public boolean modifyOpt(Integer objId, String name) {
		dao.modifyOpt(objId, name);
		return true;
	}

	public boolean addOpt(String objId, String name) {
		dao.addOpt(objId, name);
		return true;
	}

	public boolean delObj(TPiao tp) {
		return dao.delObj(tp.getId());
	}

	public void doToupiao(Integer id) {
		dao.doToupiao(id);
	}

}
